package abstractfactory.example;

import java.util.ResourceBundle;

/**
 * @author Chen Guang
 * @date 2019/4/11 0011 下午 16:28
 */
public class Test {
    public static void main(String[] args) throws Exception{

        User user = new User();
        Department department = new Department();

        //使用抽象工厂
        IFactory iFactory = new SqlserverFactory();

        IUser factoryUser = iFactory.createUser();
        factoryUser.deleteUser(user.getUserId());
        factoryUser.insertUser(user);

        IDepartment factoryDepartment = iFactory.createDepartment();
        factoryDepartment.deleteDepartment(department.getDepId());
        factoryDepartment.insertDepartment(department);

        System.out.println("---- advance ----");

        //使用简单工厂改进抽象工厂
        IDepartment iDepartment = DataAccess.createDepartment();
        iDepartment.insertDepartment(department);
        iDepartment.deleteDepartment(department.getDepId());

        IUser iUser = DataAccess.createUser();
        iUser.insertUser(user);
        iUser.deleteUser(user.getUserId());

        System.out.println("---- Reflection + properties ----");
        IDepartment departmentByReflection = DataAccess.createDepartmentByReflection();
        departmentByReflection.deleteDepartment(department.getDepId());
        departmentByReflection.insertDepartment(department);

        IUser userByReflection = DataAccess.createUserByReflection();
        userByReflection.deleteUser(user.getUserId());
        userByReflection.insertUser(user);
    }
}
